var movingShapes = (function() {
    var rectShapes = [];
    var circShapes = [];
    var startAngle = 0;

    function add(typeOfFigure) {
        if (typeOfFigure === 'rect') {
            rectShapes.push(getRandomDiv());
        }
        else if (typeOfFigure === 'circ') {
            circShapes.push(getRandomDiv());
        }
        else {
            throw 'Invalid moving shape type';
        }
    }

    function getRandomValue(min, max)
    {
        return (Math.random() * (max-min) + min | 0);
    }

    function getRandomRGBColor()
    {
        var red = getRandomValue(0, 255);
        var green = getRandomValue(0, 255);
        var blue = getRandomValue(0, 255);

        return 'rgb(' + red + ', ' + green + ', ' + blue + ')';
    }

    function getRandomDiv() {
        var div = document.createElement('div');

        div.style.width = '15px';
        div.style.height = '15px';
        div.innerText = 'div';
        div.style.borderColor = getRandomRGBColor();
        div.style.backgroundColor = getRandomRGBColor();
        div.style.color = getRandomRGBColor();
        div.style.top = getRandomValue(0, 500) + 'px';
        div.style.left = getRandomValue(0, 500) + 'px';

        return div;
    }

    function circularSpinning() {

        for (var div in circShapes) {
            div.style.left = 50 * Math.cos(startAngle) + 100 + 'px';
            div.style.top = 50 * Math.sin(startAngle) + 100 + 'px';

            startAngle += 0.1;
        }
    }

    function startAnimation() {
        setInterval('circularSpinning()', 10);
    }

    return {
        add: add,
        startAnimation: startAnimation
    };
}());

movingShapes.add('circ');
movingShapes.startAnimation();
